<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-form ref="form" :model="s_email" :rules="rules" label-width="100px" id="mvcfm">
      <div class="form-unit">
        <span class="mvc-title-left"> 消息 </span>
      </div>
      <div>
        <el-row>
          <el-col :span="24">
            <el-form-item label="我的邮箱" prop="">
              {{s_email.email}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="30">
            <el-form-item label="主题" prop="subject">
              <el-input v-model="s_email.subject" />
            </el-form-item>
          </el-col>
        </el-row>
        <input type="hidden" id="toclient" name="toclient" :value="s_email.toclient">
        <el-row>
          <el-col :span="24">
            <el-form-item label="附件" prop="">
              {{s_email.file_item_ids}}
              <el-button @click="popPubFileChoice('','file_item_ids')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="发送给" prop="replyMails">
              <el-input type="textarea" v-model="s_email.replyMails" />
              <el-button @click="popCustomerChoice('','replyMails')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <input type="hidden" id="email_password" name="email_password" :value="s_email.email_password">
        <el-row>
          <el-col :span="24">
            <el-form-item label="正文" prop="message">
              <Editor v-model="s_email.message" />
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <el-button @click="newEmailSubmit('&CMODULEID=ts_account&link_item_id='+login_user_id+'')" type='success' size="mini"><i class='fa fa-check'></i>发送</el-button>
    </el-form>
    <el-dialog :visible.sync="PubFileChoiceVisible" append-to-body>
      <PubFileChoice v-if="PubFileChoiceVisible" ref="PubFileChoice" :popparams="popparams"> </PubFileChoice>
    </el-dialog>
    <el-dialog :visible.sync="CustomerChoiceVisible" append-to-body>
      <CustomerChoice v-if="CustomerChoiceVisible" ref="CustomerChoice" :popparams="popparams"> </CustomerChoice>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import PubFileChoice from "@/views/oa/communication/PubFileChoice";
  import CustomerChoice from "@/views/oa/communication/CustomerChoice";
  export default {
    name: 'NewEmail',
    components: {
      PubFileChoice,
      CustomerChoice,
    },
    props: ['popparams'],
    data() {
      return {
        PubFileChoiceVisible: false,
        PubFileChoiceValue: null,
        PubFileChoiceDesc: null,
        CustomerChoiceVisible: false,
        CustomerChoiceValue: null,
        CustomerChoiceDesc: null,
        vueparams: this.getVUEParams(""),
        s_email: {
          email: null,
          subject: null,
          file_item_ids: null,
          replyMails: null,
          message: null,
        },
        loading: false,
        rules: {}
      }
    },
    created() {
      this.getData();
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/oa/communication/EmailAction/newEmail?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      newEmailSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/oa/communication/EmailAction/newEmailSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/oa/communication/NewEmail/newEmail?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      popPubFileChoice(desc, value) {
        this.PubFileChoiceVisible = true;
        this.PubFileChoiceDesc = desc;
        this.PubFileChoiceValue = value;
      },
      closePubFileChoice(value, desc) {
        this.PubFileChoiceVisible = false;
        this.$set(this.s_email, this.PubFileChoiceDesc, desc);
        this.$set(this.s_email, this.PubFileChoiceValue, value);
      },
      popCustomerChoice(desc, value) {
        this.CustomerChoiceVisible = true;
        this.CustomerChoiceDesc = desc;
        this.CustomerChoiceValue = value;
      },
      closeCustomerChoice(value, desc) {
        this.CustomerChoiceVisible = false;
        this.$set(this.s_email, this.CustomerChoiceDesc, desc);
        this.$set(this.s_email, this.CustomerChoiceValue, value);
      },
    },
  }
</script>
